﻿using SQLiteDB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Utils.Common;
using ZK.Entity;

namespace ZK.BLL
{
   public class UserInfoBLL
    {

        private UserInfoBLL() { }
        /// <summary>
        /// 窗体对象实例
        /// </summary>
        private static UserInfoBLL _instance;
        public static UserInfoBLL Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new UserInfoBLL();
                return _instance;
            }
        }


        public string GetNewID()
        {
            return BaseIdGenerator.Instance.GetId();
        }

        public List<UserInfo> GetList()
        {
            List<UserInfo> list;
            string sql = "Select * from UserInfo  Order BY Id ";
              list= SQLiteORM.Instance.GetEntityList<UserInfo>(sql);
            if (list == null|| list.Count==0)
            {
                list = new List<UserInfo>();
                list.Add( new UserInfo() {   Id = GetNewID() , UserId="admin", Password="admin", PersonName="管理员", PrintName="A"});
            }
            return list;
        }

        public bool InsertList(List<UserInfo> list)
        {
            foreach (var item in list)
            {
                item.Id = GetNewID();
            }
            return SQLiteORM.Instance.InsertListByTransaction<UserInfo>(list);
        }


        public bool DeleteAll()
        {
            return SQLiteORM.Instance.Delete("Delete from UserInfo");
        }

    }
}
